package com.smallkingson.ylib.core.utils;

public  class YIntervalRuner {
        long interval;
        long lastRunTime;


        public YIntervalRuner(long interval) {
            this.interval = interval;
            lastRunTime = System.currentTimeMillis();
        }

        public void run(OnIntervalRunListener onIntervalRunListener, Object... tags) {

            long curr = System.currentTimeMillis();
            if (curr - lastRunTime < interval) {
                onIntervalRunListener.onNo(tags);
                return;
            }
            onIntervalRunListener.onYes(tags);
            lastRunTime = curr;
        }

        public static interface OnIntervalRunListener {

            abstract void onYes(Object[] tags);

            abstract void onNo(Object[] tags);
        }
    }